<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>直接导出测试</title>
    <style>
        body { 
            font-family: Arial, sans-serif; 
            margin: 40px; 
            line-height: 1.6;
        }
        .export-link {
            display: inline-block;
            padding: 15px 25px;
            background: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 5px;
            margin: 10px;
            font-size: 16px;
        }
        .export-link:hover {
            background: #0056b3;
            color: white;
            text-decoration: none;
        }
        .token-input {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            font-family: monospace;
            font-size: 12px;
        }
        .status {
            padding: 10px;
            margin: 10px 0;
            border-radius: 5px;
        }
        .success { background: #d4edda; color: #155724; }
        .error { background: #f8d7da; color: #721c24; }
        .info { background: #d1ecf1; color: #0c5460; }
    </style>
</head>
<body>
    <h1>直接导出测试工具</h1>
    <p>这个页面用于直接测试导出功能，绕过所有复杂的前端逻辑</p>

    <div class="status info">
        <strong>说明：</strong>请先从线索管理页面获取登录token，然后使用下面的链接直接导出数据
    </div>

    <h3>步骤1：输入Token</h3>
    <input type="text" id="tokenInput" class="token-input" placeholder="请输入从localStorage获取的adminToken">
    <button onclick="updateLinks()">更新导出链接</button>

    <h3>步骤2：选择导出方式</h3>
    <div id="exportLinks">
        <p>请先输入token</p>
    </div>

    <h3>步骤3：获取Token的方法</h3>
    <div class="status info">
        1. 在线索管理页面按F12打开开发者工具<br>
        2. 在Console标签页输入：<code>localStorage.getItem('adminToken')</code><br>
        3. 复制得到的token（去掉引号）粘贴到上面的输入框中
    </div>

    <script>
        function updateLinks() {
            const token = document.getElementById('tokenInput').value.trim();
            const linksDiv = document.getElementById('exportLinks');
            
            if (!token) {
                linksDiv.innerHTML = '<div class="status error">请先输入token</div>';
                return;
            }
            
            const baseUrl = '/api/admin/clues/export';
            const params = `format=excel&token=${encodeURIComponent(token)}`;
            
            linksDiv.innerHTML = `
                <a href="${baseUrl}?${params}" class="export-link" download>导出全部线索</a><br>
                <a href="${baseUrl}?${params}&clue_ids=1,2" class="export-link" download>导出ID为1,2的线索</a><br>
                <a href="${baseUrl}?${params}&clue_ids=1,2,3" class="export-link" download>导出ID为1,2,3的线索</a><br>
                <a href="${baseUrl}?${params}&format=csv" class="export-link" download>导出CSV格式</a><br>
                
                <div class="status success" style="margin-top: 20px;">
                    <strong>导出链接已生成！</strong><br>
                    点击上面的链接即可直接下载对应的数据文件
                </div>
            `;
        }
        
        // 页面加载时尝试自动获取token
        window.addEventListener('load', function() {
            const token = localStorage.getItem('adminToken');
            if (token) {
                document.getElementById('tokenInput').value = token;
                updateLinks();
                
                const status = document.createElement('div');
                status.className = 'status success';
                status.innerHTML = '<strong>自动检测到token！</strong>导出链接已自动生成';
                document.body.insertBefore(status, document.querySelector('h3'));
            }
        });
    </script>
</body>
</html> 